package users

import (
	"goskeleton/app/global/consts"
	"goskeleton/app/http/controller/web"
	"goskeleton/app/http/validator/core/data_transfer"
	"goskeleton/app/utils/response"

	"github.com/gin-gonic/gin"
)

// UserAssociateEmployee 用户关联员工验证器
type UserAssociateEmployee struct {
	UserId     float64 `form:"user_id" json:"user_id" binding:"required,min=1"`
	EmployeeId float64 `form:"employee_id" json:"employee_id" binding:"min=0"` // 允许为0，表示取消关联
	PostMemberId float64 `form:"post_member_id" json:"post_member_id" binding:"min=0"` // 允许为0，表示取消关联
}

func (p UserAssociateEmployee) CheckParams(context *gin.Context) {
	if err := context.ShouldBind(&p); err != nil {
		response.ValidatorError(context, err)
		return
	}

	extraAddBindDataContext := data_transfer.DataAddContext(p, consts.ValidatorPrefix, context)
	if extraAddBindDataContext == nil {
		response.ErrorSystem(context, "UserAssociateEmployee表单验证器json化失败", "")
	} else {
		(&web.Users{}).AssociateEmployee(extraAddBindDataContext)
	}
}
